﻿using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using élénkPróbája.extentions;
using élénkPróbája.native.rule;
using élénkPróbája.Test.dto;
using élénkPróbája.Test.extention;

namespace élénkPróbája.Test
{
    [TestClass]
    public class ChainingValidatorsTester
    {
        TestValidator validator;
        public ChainingValidatorsTester()
        {
            validator = new TestValidator();
        }
        [TestMethod]
        public void Should_create_multiple_validators()
        {
            validator.RuleFor(x => x.Name)
                .NotNull()
                .NotEqual("foo");

            validator.Cast<PropRule>().Single().Validators.Count().ShouldEqual(2);
        }
        [TestMethod]
        public void Should_execute_multiple_validators()
        {
            validator.RuleFor(x => x.Name).NotNull()
                .Equal("Foo");

            validator.Validate(new Company()).Errors.Count().ShouldEqual(2);
        }
        [TestMethod]
        public void Options_should_only_apply_to_current_validator()
        {
            validator.RuleFor(x => x.Name).NotNull()
                .WithMessage("null")
                .Equal("foo")
                .WithMessage("equal");

            var results = validator.Validate(new Company());
            results.Errors.ElementAt(0).ErrorMessage.ShouldEqual("null");
            results.Errors.ElementAt(1).ErrorMessage.ShouldEqual("equal");
        }
    }
}
